package com.intellagric.common.pojo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用的响应实体类
 */
public class ResponseMessage implements Serializable {

    //状态码 200-成功 100-失败
    private int code;

    //总记录数
    private long total;

    //对应状态码的提示信息
    private String message;

    //用户要返回给浏览器的数据
    private Map<String, Object> data = new HashMap<String, Object>();

    //使用默认的成功message
    public static ResponseMessage success() {
        ResponseMessage result = new ResponseMessage();
        result.setCode(200);
        result.setMessage("请求成功！");
        return result;
    }

    //使用默认的失败message
    public static ResponseMessage fail() {
        ResponseMessage result = new ResponseMessage();
        result.setCode(100);
        result.setMessage("请求失败！");
        return result;
    }

    //可设置成功message
    public static ResponseMessage success(String message) {
        ResponseMessage result = new ResponseMessage();
        result.setCode(200);
        result.setMessage(message);
        return result;
    }

    //可设置失败的message
    public static ResponseMessage fail(String message) {
        ResponseMessage result = new ResponseMessage();
        result.setCode(100);
        result.setMessage(message);
        return result;
    }

    public ResponseMessage add(String key, Object value) {
        this.getData().put(key, value);
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
